package cn.itsource.pethome.org.service.impl;

import cn.itsource.pethome.basic.service.impl.BaseServiceImpl;
import cn.itsource.pethome.org.domain.Employee;
import cn.itsource.pethome.org.mapper.EmployeeMapper;
import cn.itsource.pethome.org.service.IEmployeeService;
import cn.itsource.pethome.user.domain.LoginInfo;
import cn.itsource.pethome.user.mapper.LoginInfoMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class EmployeeServiceImpl extends BaseServiceImpl<Employee> implements IEmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;

    @Autowired
    private LoginInfoMapper loginInfoMapper;

    @Override
    @Transactional
    public void save(Employee employee) {
        //员工对象转为登录信息
        LoginInfo loginInfo = employee2LoginInfo(employee);
        //保存登录信息
        loginInfoMapper.save(loginInfo);
        //设置登录信息
        employee.setLoginInfo(loginInfo);
        //保存员工信息
        super.save(employee);
    }

    private LoginInfo employee2LoginInfo(Employee employee) {
        LoginInfo loginInfo = new LoginInfo();
        BeanUtils.copyProperties(employee,loginInfo);
        //后端
        loginInfo.setType(false);
        return loginInfo;
    }
}
